package com.wlstock.funi.model;


import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.wlstock.funi.fundenum.KLINE_PERIOD;

import java.util.Date;

/**
 * Created by admin on 16/9/24.
 */

@DatabaseTable
public class SelfFundHisModel extends BaseModel {
    @DatabaseField( generatedId = true)
    private int id ;
    @DatabaseField
    private String stkName;
    @DatabaseField(uniqueCombo = true, index = true)
    private String stkCode;
    @DatabaseField(uniqueCombo = true, index = true)
    private KLINE_PERIOD KLINEPeriod;
    @DatabaseField(uniqueCombo = true, index = true)
    private String periodStr;
    @DatabaseField(uniqueCombo = true, index = true)
    private Date   realDate;
    @DatabaseField
    private Date   lastUpdateDate = new Date();

    @DatabaseField
    private float open;
    @DatabaseField
    private float high;
    @DatabaseField
    private float low;
    @DatabaseField
    private float close;

    @DatabaseField//5个周期的均值,以下类推
    private float ma5;
    @DatabaseField
    private float ma10;
    @DatabaseField
    private float ma30;
    @DatabaseField
    private float ma60;

    @DatabaseField
    private float atr1;
    @DatabaseField
    private float atr2;
    @DatabaseField
    private float atr3;
    @DatabaseField
    private float atr4;
    @DatabaseField
    private float atr5;
    @DatabaseField
    private float atr6;

    private SelfFundHisModel(){}

    public SelfFundHisModel(StrategyFundModel fundModel) {
        this(fundModel.getStkName(), fundModel.getStkNo());
    }

    public SelfFundHisModel(String stkName, String stkCode) {
        this.stkName = stkName;
        this.stkCode = stkCode;
    }

    public long getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getStkName() {
        return stkName;
    }

    public void setStkName(String stkName) {
        this.stkName = stkName;
    }

    public String getStkCode() {
        return stkCode;
    }

    public void setStkCode(String stkCode) {
        this.stkCode = stkCode;
    }

    public KLINE_PERIOD getKLINEPeriod() {
        return KLINEPeriod;
    }

    public void setKLINEPeriod(KLINE_PERIOD KLINEPeriod) {
        this.KLINEPeriod = KLINEPeriod;
        //同时初始化Str
        setPeriodStr(KLINEPeriod);
    }

    public Date getRealDate() {
        return realDate;
    }

    public void setRealDate(Date realDate) {
        this.realDate = realDate;
    }

    public Date getLastUpdateDate() {
        return lastUpdateDate;
    }

    public void setLastUpdateDate(Date lastUpdateDate) {
        this.lastUpdateDate = lastUpdateDate;
    }

    public float getMa5() {
        return ma5;
    }

    public void setMa5(float ma5) {
        this.ma5 = ma5;
    }

    public float getMa10() {
        return ma10;
    }

    public void setMa10(float ma10) {
        this.ma10 = ma10;
    }

    public float getMa60() {
        return ma60;
    }

    public void setMa60(float ma60) {
        this.ma60 = ma60;
    }

    public float getMa30() {
        return ma30;
    }

    public void setMa30(float ma30) {
        this.ma30 = ma30;
    }

    private void setPeriodStr(KLINE_PERIOD KLINEPeriod){
        periodStr = deliverPeriodToStr(KLINEPeriod);
    }

    public static String deliverPeriodToStr(KLINE_PERIOD KLINEPeriod){
        String tmpStr = "NONE";
        switch (KLINEPeriod){
            case MIN5:
                tmpStr = "MIN5";
                break;
            case MIN10:
                tmpStr = "MIN10";
                break;
            case MIN30:
                tmpStr = "MIN30";
                break;
            case MIN60:
                tmpStr = "MIN60";
                break;
            case DAY:
                tmpStr = "DAY";
                break;
            case NONE:
                tmpStr = "NONE";
            default:
                tmpStr = "NONE";
                break;
        }
        return tmpStr;
    }

    public float getOpen() {
        return open;
    } public void setOpen(float open) {
        this.open = open;
    } public float getHigh() {
        return high;
    } public void setHigh(float high) {
        this.high = high;
    } public float getLow() {
        return low;
    } public void setLow(float low) {
        this.low = low;
    } public float getClose() {
        return close;
    } public void setClose(float close) {
        this.close = close;
    }

    public String getPeriodStr(){
        return periodStr;
    }

    public float getAtr1() {
        return atr1;
    }

    public void setAtr1(float atr1) {
        this.atr1 = atr1;
    }

    public float getAtr2() {
        return atr2;
    }

    public void setAtr2(float atr2) {
        this.atr2 = atr2;
    }

    public float getAtr3() {
        return atr3;
    }

    public void setAtr3(float atr3) {
        this.atr3 = atr3;
    }

    public float getAtr4() {
        return atr4;
    }

    public void setAtr4(float atr4) {
        this.atr4 = atr4;
    }

    public float getAtr5() {
        return atr5;
    }

    public void setAtr5(float atr5) {
        this.atr5 = atr5;
    }

    public float getAtr6() {
        return atr6;
    }

    public void setAtr6(float atr6) {
        this.atr6 = atr6;
    }

    public SelfFundHisModel clone() throws CloneNotSupportedException {
        return (SelfFundHisModel) super.clone();
    }

    public void setDatas(float open, float high, float low, float close, float ma_price5, float ma_price10, float ma_price30, Date date) {
        setOpen(open);
        setHigh(high);
        setLow(low);
        setClose(close);
        setMa5(ma_price5);
        setMa10(ma_price10);
        setMa30(ma_price30);
        setRealDate(date);
    }
}
